package com.tangkun.environment.view;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.tangkun.environment.R;
import com.tangkun.environment.utils.Utils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 审核对话框
 *
 * @author TangKun
 */
public class ShenHeDialog extends Dialog {
    @BindView(R.id.et_shenhe_content)
    EditText etShenheContent;
    @BindView(R.id.btn_shenhe_tongguoshenhe)
    Button btnShenheTongguoshenhe;
    @BindView(R.id.btn_shenhe_dahuichongshen)
    Button btnShenheDahuichongshen;
    @BindView(R.id.fl_shenhe)
    FrameLayout flShenhe;
    @BindView(R.id.iv_shenhe_dismiss)
    ImageView ivShenheDismiss;
    @BindView(R.id.relativeLayout)
    RelativeLayout relativeLayout;
    private Context context;
    private View view;

    /**
     * @param context 上下文
     */
    public ShenHeDialog(Context context) {
        super(context, R.style.InvitationDialogStyle);
        this.context = context;
        view = initView();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_ACTION_BAR);
        requestWindowFeature(Window.PROGRESS_INDETERMINATE_ON);
        super.onCreate(savedInstanceState);
        DisplayMetrics dm = new DisplayMetrics();
        getWindow().getWindowManager().getDefaultDisplay().getMetrics(dm);
        getWindow().setWindowAnimations(R.style.InvitationDialogStyle);
        view = initView();
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(dm.widthPixels, dm.heightPixels);
        addContentView(view, lp);
        setCanceledOnTouchOutside(true);
    }


    private View initView() {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_shenhe, null);
        ButterKnife.bind(this, view);
        return view;
    }


    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    private OnClickListener onClickListener;

    @OnClick({R.id.btn_shenhe_tongguoshenhe, R.id.btn_shenhe_dahuichongshen, R.id.iv_shenhe_dismiss})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_shenhe_tongguoshenhe://通过审核
                Utils.hideSoftKeyboard((Activity) context, ivShenheDismiss);
                dismiss();
                if (onClickListener != null) {
                    String content = etShenheContent.getText().toString().trim();
                    onClickListener.access(content);
                }
                break;
            case R.id.btn_shenhe_dahuichongshen://打回重申
                Utils.hideSoftKeyboard((Activity) context, ivShenheDismiss);
                dismiss();
                if (onClickListener != null) {
                    String content = etShenheContent.getText().toString().trim();
                    onClickListener.refuse(content);
                }
                break;
            case R.id.iv_shenhe_dismiss://关闭对话框
                Utils.hideSoftKeyboard((Activity) context, ivShenheDismiss);
                dismiss();
                break;
        }
    }

    public interface OnClickListener {
        void access(String content);

        void refuse(String content);
    }
}
